﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LMM_Editor.Classes.System;
using System.Drawing;
using Azuria.Common.Controls;
using System.IO;

namespace LMM_Editor.Forms
{
    public partial class Editor : Form
    {
        public InputHandler inputHandler = new InputHandler();

        public Editor()
        {
            InitializeComponent();
            LMMSystem.Initialise();

            initData();
            inputHandler.toolManager.parent = Data.editorPanel;

        }

        public void initData()
        {
            PropertyGrid propertiesGrid = (PropertyGrid)this.Controls.Find("propertiesGrid", true)[0];
            FilteredPropertyGrid fgrid = new FilteredPropertyGrid();
            Data.propertiesGrid = propertiesGrid;
            fgrid.BrowsableProperties = new string[] { "Size" };
            //fgrid.Location = propertiesGrid.Location;
            //fgrid.Size = propertiesGrid.Size;

            this.Controls.Add(fgrid);
            //this.Controls.Remove(propertiesGrid);

            Data.editorPanel = (Panel)this.Controls.Find("editorPanel", true)[0];
        }

        public void panel1_DragEnd(object sender, DragEventArgs e)
        {
            Control c = (Control)sender;
            c.Location = new Point(e.X, e.Y);
        }

        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            inputHandler.onClick(e.X, e.Y, (Control)sender);
        }

        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            // Process mouse click
            inputHandler.onClickRelease(e.X, e.Y, (Control)sender);
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            inputHandler.toolManager.setToolIndex(ToolType.Select);
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            inputHandler.toolManager.setToolIndex(ToolType.Create);
        }

        private void saveToolStripButton_Click(object sender, EventArgs e)
        {
            saveFileDialog1.ShowDialog();
            if (saveFileDialog1.FileName != "")
            {
                FileManager.saveFile(saveFileDialog1.FileName);
            }
        }
    }
}